Page({
  data: {
    messages: [],
    inputValue: ''
  },
  onLoad: function(options) {
    const chatObjectId = options.id || '未知对象';
    wx.setNavigationBarTitle({
      title: `私聊对象: ${chatObjectId}`
    });

    // 模拟加载历史消息
    this.setData({
      messages: [
        // 你好，有什么可以帮助你的吗
        { id: 1, content: 'Surprise! Mother Fucker!', from: 'other' },
      ]
    });
  },
  inputChange: function(e) {
    this.setData({
      inputValue: e.detail.value
    });
  },
  sendMessage: function() {
    if (this.data.inputValue.trim() === '') return;

    const newMessage = {
      id: this.data.messages.length + 1,
      content: this.data.inputValue,
      from: 'self'
    };

    // 更新消息列表
    this.setData({
      messages: [...this.data.messages, newMessage],
      inputValue: ''
    });

    // 模拟自动回复
    setTimeout(() => {
      const autoReply = {
        id: this.data.messages.length + 1,
        content: '大傻春!,你要干神马',
        from: 'other'
      };
      this.setData({
        messages: [...this.data.messages, autoReply]
      });
    }, 1000);
  }
});
